#include "sha256.h"

int main() {
    data_t text = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};

    unsigned char ref[SHA256_BLOCK_SIZE] = {0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1};

    int has_errors = 0;

    unsigned char buf[SHA256_BLOCK_SIZE];
    SHA256_CTX ctx;

    sha256_init(&ctx);
    sha256_update(
        &(ctx.data),
        &(ctx.datalen),
        &(ctx.state),
        &(ctx.bitlen),
        &text,
        strlen(reinterpret_cast<const char *>(text)));
    sha256_final(&ctx, buf);

    // test for encode result
    for (int i = 0; i < SHA256_BLOCK_SIZE; i++) {
        if (buf[i] != ref[i]) {
            printf("buf[%d] = 0x%x, expect_buf[%d] = 0x%x\n",
                   i,
                   buf[i],
                   i,
                   ref[i]);
            has_errors++;
        }
    }

    if (has_errors) {
        fprintf(stderr, "Benchmark results are incorrect\n");
        return -1;
    }

    printf("Success.\n");
    return 0;
}
